<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>


    <link rel="stylesheet" type="text/css" href="../css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="../css/pages-register.css" />
<!--	<style type="text/css">
		/*给点击获取验证码按钮设置样式*/
		.btn {
			border: 0;
			width:120px;
			height:40px;
			line-height: 40px;
			float:left;
			color: white;
			background-color: #08c;
			border-radius: 20px;
			text-align: center;
			text-decoration: none;
		}
	</style>-->
</head>

<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="" class="logo-bd"></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="/user/toLogin" target="_blank">登陆</a></span></h3>
			<div class="info">
				<form class="sui-form form-horizontal">
					<div class="control-group">
						<label class="control-label">用户名：</label>
						<div class="controls">
							<input type="text" onmouseout="checkUsername()" id="usernameId" placeholder="请输入你的用户名" class="input-xfat input-xlarge">
							<span id="tipsId"></span>
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" id="passwordId" placeholder="设置登录密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" placeholder="再次确认密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">邮箱：</label>
						<div class="controls">
							<input type="text" id="emailId" placeholder="请输入邮箱" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" id="phoneId" placeholder="请输入你的手机号" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label for="inputPassword" class="control-label">短信验证码：</label>
						<div class="controls">
							<input type="text" id="codeId" placeholder="短信验证码" class="input-xfat input-xlarge">
							<button type="button" onclick="sendCode()" id="getCodeId">点击获取验证码</button>
						</div>
					</div>
					
					<div class="control-group">
						<label for="inputPassword" class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《东东商城用户协议》</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a class="sui-btn btn-block btn-xlarge btn-danger" href="javascript:addUser();">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机东东商城</li>
				<li>销售联盟</li>
				<li>东东商城社区</li>
			</ul>
			<div class="address">地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</div>
			<div class="beian">京ICP备08006666号京公网安备11010888888
			</div>
		</div>
	</div>


<script type="text/javascript" src="../js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="../js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="../js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="../js/pages/register.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>

</body>
<script>

	//当用户鼠标移除用户名输入框就校验，该账号是否存在
	function checkUsername(){
		var username = $("#usernameId").val();

		$.ajax({
            url:"/user/getUserByUsername",
            type:"post",
            dataType:"json",
            data:{username:username},
            async:false,
            success:function(result){
                var result = result.data;
                if(result.code){
                  $("#tipsId").attr("style","color: red");
                  $("#tipsId").html(result.message);
                }else{
					$("#tipsId").attr("style","color: lawngreen");
					$("#tipsId").html(result.message);
				}
            },
            error:function(){
                alert("系统异常");
            }
        })
	}


	//发送验证码
	function sendCode(){
		//获取手机号
		var phone = $("#phoneId").val();
		if(phone == ''){
			alert("请输入手机号");
			return;
		}

		$.ajax({
			url:"/user/sendCode",
			type:"post",
			dataType:"json",
			data:{phone:phone},
			async:false,
			success:function(result){
				//如果系统发送成功
				if(result.code==200){
					//调用获取验证码按钮六十秒之后重试
					settime($("#getCodeId"));
				}
			},
			error:function(){
				alert("系统异常");
			}
		})
	};

	//获取验证码按钮六十秒之后重试
	var time = 60;
	function settime(obj){
		if (time==0) {
			$(obj).attr('disabled', false);
			$(obj).html("点击获取验证码");
			time = 60;
			return;
		} else{
			$(obj).attr('disabled', true);
			$(obj).html(time+"秒后重新发送");
			time--;
		}
		setTimeout(function() {
			settime(obj)
		},1000)
	}


	//保存用户
	function addUser(){
		//获取用户名
		var username = $("#usernameId").val();
		//获取密码
		var password = $("#passwordId").val();
		//获取手机号
		var phone = $("#phoneId").val();
		//验证码
		var code = $("#codeId").val();
		//邮箱
		var email = $("#emailId").val();
		$.ajax({
			url:"/user/addUser",
			type:"post",
			dataType:"json",
			data:{username:username,password:password,phone:phone,code:code,email:email},
			async:false,
			success:function(result){
				if(result.code==200){
					alert("注册成功");
					location.href="/user/toLogin";
				}
			},
			error:function(){
				alert("系统异常");
			}
		})

	}


</script>
</html>